package controllers

import (
	"egin/app/service"
	"encoding/json"
	"net/http"

	"github.com/gin-contrib/sessions"
	"github.com/gin-gonic/gin"
)

//Apphtml
func AppHtml(c *gin.Context) {
	sesssion := sessions.Default(c)
	member_info := sesssion.Get("member_info")
	ls_load := sesssion.Get("ls_load")
	id := sesssion.Get("id")

	if member_info == nil || ls_load != nil {
		member, _ := service.GetMember(id.(string))
		member_json, err := json.Marshal(member)
		if err == nil {
			member_info = string(member_json)
			sesssion.Set("member_info", member_info)
			sesssion.Delete("ls_load")
			sesssion.Save()
		}
	}

	c.HTML(http.StatusOK, "app/app.tmpl", gin.H{
		"member": member_info.(string),
	})
}

//AppInit
func AppInit(c *gin.Context) {

	data := service.GetNavs(c)

	c.JSON(http.StatusOK, data)
}

func AppSettingHtml(c *gin.Context) {

	c.HTML(http.StatusOK, "app/setting.tmpl", nil)
}

func AppAlertSkinHtml(c *gin.Context) {

	c.HTML(http.StatusOK, "app/alertSkin.tmpl", nil)
}
